//
//  NSDate+WZPDate.m
//  WZPItem
//
//  Created by 王王喆平 on 16/7/17.
//  Copyright © 2016年 UI. All rights reserved.
//

#import "NSDate+WZPDate.h"

@implementation NSDate (WZPDate)

-(NSDateComponents *)dataWithNow{
    
    // 获取当前时间
    NSDate * currently = [NSDate date];
    // 获取日历
    NSCalendar * calendar = [NSCalendar currentCalendar];
    
    // 返回当前的时间差
    return [calendar components:NSCalendarUnitHour | NSCalendarUnitMinute fromDate:self toDate:currently options:NSCalendarWrapComponents];
    
}
-(BOOL)isThisyear{
    
    NSDate * currently = [NSDate date];
    NSCalendar * calendar = [NSCalendar currentCalendar];
    
    // 获取当前日期组件
    NSDateComponents * curcom = [calendar components:NSCalendarUnitYear fromDate:currently];
    // 获取发布时的日期组件
    NSDateComponents * postcom = [calendar components:NSCalendarUnitYear fromDate:self];
    // 判断发布年份于现在年份是否相等
    return  curcom.year == postcom.year;
    
}
-(BOOL)isYesterday{
    
    NSCalendar * calendar = [NSCalendar currentCalendar];
    return [calendar isDateInYesterday:self];
        
}
-(BOOL)isToday{
    
    NSCalendar * calendar = [NSCalendar currentCalendar];
    return [calendar isDateInToday:self];
}

@end
